package com.geeaks.learn.guava.eventbus;

import org.junit.Test;
import com.google.common.eventbus.EventBus;

public class EventBusTest {
	
	@Test
	public void testReceiveEvent() throws Exception {
		EventBus eventBus = new EventBus("test");
		EventListener listener = new EventListener();
		eventBus.register(listener);
		eventBus.post(new TestEvent(200));
		System.out.println("LastMessage:" + listener.getLastMessage());
	}
	
	@Test
	public void testMultipleEvents() throws Exception {
		EventBus eventBus = new EventBus("test");
		MultipleListener multiListener = new MultipleListener();
		eventBus.register(multiListener);
		eventBus.post(new Integer(100));
		eventBus.post(new Integer(200));
		eventBus.post(new Integer(300));
		eventBus.post(new Long(800));
		eventBus.post(new Long(800990));
		eventBus.post(new Long(800882934));
		System.out.println("LastInteger:" + multiListener.getLastInteger());
		System.out.println("LastLong:" + multiListener.getLastLong());
	}
	
	@Test
	public void testDeadEventListeners() throws Exception {
		EventBus eventBus = new EventBus("test");
		DeadEventListener deadEventListener = new DeadEventListener();
		eventBus.register(deadEventListener);
//		EventListener listener = new EventListener();
//		eventBus.register(listener);
		eventBus.post(new TestEvent(200));
		eventBus.post(new TestEvent(300));
		System.out.println("deadEvent:" + deadEventListener.isNotDelivered());
	}
}
